﻿//
// Created by Administrator on 2022/1/18.
//

#include <wx/msw/private.h>
#include "MyDialog.h"
#include "ids.h"
#include "action_event.h"
#include "../../monitorDir/src/MyDialog.h"
#include "../../ViewDemos/WorkThread/src/MyDialog.h"
#include "../../board/src/MyDialog.h"


BEGIN_EVENT_TABLE ( MyDialog, wxFrame )
                EVT_BUTTON ( ID_BUTTON_POST_MESSAGE, MyDialog::OnStartPost )
END_EVENT_TABLE()

MyDialog::MyDialog(wxWindow *parent):wxFrame( parent, wxID_ANY, "abc" ) {
    //SetTitle("abc");
    SetClientSize ( wxSize ( 350, 500 ) );
    dialogRootBoxSizer = new wxBoxSizer ( wxVERTICAL );
    m_filePicker1 = new wxFilePickerCtrl ( this, ID_FILE_PICKER, wxEmptyString,
            wxT ( "Select a file" ), wxT ( "*.*" ),
            wxDefaultPosition, wxDefaultSize, wxFLP_DEFAULT_STYLE );
    dialogRootBoxSizer->Add ( m_filePicker1, 0, wxALL | wxEXPAND, 5 );
    cb_isDelete = new wxCheckBox( this, ID_DELETE_FILE, wxT("Delete File After Finishing?"),
                                  wxDefaultPosition, wxDefaultSize, 0 );
    dialogRootBoxSizer->Add ( cb_isDelete, 0, wxALL | wxEXPAND, 5 );
    button = new wxButton ( this, ID_BUTTON_POST_MESSAGE, "发送消息" );
    dialogRootBoxSizer->Add ( button, 0, wxALL | wxEXPAND, 5 );
    this->SetSizer( dialogRootBoxSizer );
}



MyDialog::~MyDialog() {

}

static void printAddr( void * p ){
    wxString tmp;
    tmp.sprintf(wxT("%p"), p );
    wxMessageBox( tmp, "地址");
}

void MyDialog::OnStartPost( wxCommandEvent &event ) {
    //wxMessageBox( "abc", "cdb");
    //wxFindWindowB
    //wxWindow* w = FindWindowById(ID_FRAME_REPOSITORY);
    //wxWindow* w = wxFindWindowByLabel("Transfer");
    //w = wxFindWindowByName( "Transfer" );
    //FindWindowCaption
    //hwnd 转wxwindow
    HWND hwnd = ::FindWindow(nullptr, _T("Transfer"));
    //w = wxWindow::CreateWindowFromHWND(nullptr, hwnd );
    //WXHWND wxhwnd;
    //w = wxGetWindowFromHWND((WXHWND)hwnd);
    //wxWindow win;
    //win.SetHWND((WXHWND)hwnd);
    //wxString label = win.GetLabel();
    //win.Close();
    //return;
    //wchar_t msg[] = wxT("女孩不哭");
    //cds.lpData = msg;
    //cds.cbData = wcsnlen_s(msg, 50)+1; //字符串请记得把'\0'加上, 不然就错了, 这里是ANSI字符串
    //cds.cbData = wcslen(msg);

    //auto *path = new wxString( wxT("G:\\eMule\\eMule\\Incoming\\heyzo_hd_1407_full.mp4" ) );
    //wchar_t *s = new wchar_t (150);
    //memcpy_s( s, 150, wxT("G:\\eMule\\eMule\\Incoming\\heyzo_hd_1407_full.mp4" ), 50 );
    //LPARAM p = &s;
    //int z = 3;
    //int * z = new int;
    //*z = 3;
    //WPARAM ww = (WPARAM )z ;
    //printAddr( z );
    //printAddr( &label );
    //printAddr( &cds );
    //WXWPARAM g;
    //g = ww;
    //wxMessageBox();
    //::SendMessage( hwnd, WM_USER+1, ww, (LPARAM)&label );
    //::SendMessage( hwnd, WM_COPYDATA, 0, (LPARAM)&path );
    //const UINT myMsg = RegisterWindowMessage(wxT("MY_MESSAGE"));
    //::SendMessage( hwnd, myMsg, z, (LPARAM)&msg );
    wxString tmp = this->m_filePicker1->GetPath();
    //tmp.GetData();
    //memcpy
    //wxString path = wxT("123");//(tmp.GetData());
    wxCStrData data = tmp.GetData();
    //data.AsWChar();
    wxScopedWCharBuffer buf = data.AsWCharBuf();
    //CharType type = buf.data();
    size_t ss = tmp.Len();
    size_t s = buf.length() + 1;
    wchar_t *buff = new wchar_t [buf.length()+1];
    wcscpy_s( buff, buf.length()*2+1, buf.data() );
    //wxString path = buff;
    //path.sprintf("%s", tmp.GetData() );
    //if( path.IsSameAs(_T("")))
    //    return;
    if ( hwnd ) {
        COPYDATASTRUCT cds;
        //wxString msg = wxT("女孩不哭");
        if( cb_isDelete->GetValue() ){
            cds.dwData = 1;
        }else {
            cds.dwData = 0;
        }
        cds.lpData = buff;
        cds.cbData = s*2;
        ::SendMessage(hwnd, WM_COPYDATA, 0, (LPARAM) &cds);
    }
    //wxString tmp = wxT("TEST");
    //ActionEvent actionEvent( &win, TOKEN_LOG, tmp );
    //actionEvent.Post();
    //if( buff)
        //delete buff;
    //wxFileName c(wxT("c:\\"));
    //this->m_filePicker1->SetFileName(c);
}



